/******************************************************************
 * Created by: DO HOANG HAI                                       
 * Date of Creation: 25/Aug/2007                                               
 * Date of last modification: 15th/Sep/2007
 *                                                                
 * Description:  Provide methods to access, manipulate items in the
 * database.
 * 
 * Status: Optimized and Finished
 ******************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Pbdms.Common.DataObject;
using Pbdms.DataAccess.DataProvider;

namespace Pbdms.BusinessLogic.DataController
{
    /// <summary>
    /// Provide methods to access, manipulate items in the database.
    /// </summary>
    public class ItemController
    {
        public ItemController()
        {
        }
        /// <summary>
        /// create an instance
        /// </summary>
        /// <returns></returns>
        public static ItemController create()
        {
            return new ItemController();
        }
        /// <summary>
        /// get arraylist of all the items in the database.
        /// </summary>
        /// <returns></returns>
        public ArrayList getListOfAllItems()
        {
            return ItemProvider.getListOfAllItems();
        }

        /// <summary>
        /// get the list of items by category
        /// </summary>
        /// <param name="categoryName">category name (with refer to database)</param>
        /// <returns></returns>
        public ArrayList getListOfItemsByCategory(String categoryName)
        {
            return ItemProvider.getListOfItemsByCategory(categoryName);
        }

        /// <summary>
        /// delete an item with given Id
        /// </summary>
        /// <param name="itemObjId"></param>
        public void deleteItem(String itemObjId)
        {
            ItemProvider.create(itemObjId).deleteDB();
        }

        /// <summary>
        /// update an item to database
        /// </summary>
        /// <param name="itemObj"></param>
        public void updateItemToDB(Item itemObj)
        {
            ItemProvider.create(itemObj).updateAllToDB();
        }

        /// <summary>
        /// get item object from database with given id
        /// </summary>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public Item getItemFromDB(string itemID)
        {
            return ItemProvider.create(itemID).selectFromDB();
        }

        /// <summary>
        /// get list of item Ids of all items in the database.
        /// </summary>
        /// <returns></returns>
        public ArrayList getListOfItemIDs()
        {
            return ItemProvider.getListOfAllItemsId();
        }
        /// <summary>
        /// append an item object to the database
        /// </summary>
        /// <param name="itemObj"></param>
        public void appendItem(Item itemObj)
        {
            ItemProvider.appendItem(itemObj);
        }
    }
}
